package com.ewhale.feitengguest.presenter.user.mine;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.view.user.mine.ResetSeconeView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;

public class ResetSeconePresenter extends IPresenter {
    private String user_resetPhone = "app/account/updatePhoneToNew.json";
    private String shop_resetPhone = "app/shop/updatePhoneToNew.json";

    public void getCode(String sessionId,String phone) {
        mView.showProLoading();
        request(1, ApiHelper.AUTH_API.getCode(sessionId,phone, "3"), null);
    }

    public void resetPhone(int apptype, String phone, String phoneCode, String token) {
        mView.showProLoading();
        request(2, ApiHelper.AUTH_API.resetPhone(apptype == 1 ? user_resetPhone : shop_resetPhone, phone, phoneCode, token), null);
    }

    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode) {
            case 1:
                ((ResetSeconeView) mView).getCodeSuccess();
                break;
            case 2:
                ((ResetSeconeView) mView).resetSuccess();
                break;
        }
    }

    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode, e.getCode(), e.getDisplayMessage());
    }
}
